package com.itdragon.cloud.eurekaServer.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@Service
public class HelloWorldService {
	
	@Autowired
	private RestTemplate restTemplate;
	
	// @HystrixCommand注解。该注解对该方法创建了熔断器的功能，并指定了fallbackMethod熔断方法
	@HystrixCommand(fallbackMethod = "hystrixMethod")
	public String sayHello(String world) {
		return restTemplate.getForObject("http://EUREKA-DEMO/helloworld?hello=" + world, String.class);
	}
	
	// 要带参数
	public String hystrixMethod (String world) {
		return "Error : Hystrix - Fallback - Method - " + world;
	}

}
